//
//  UIImage.swift
//  Documentation
//
//  Created by Toj on 2/7/23.
//

import Foundation

extension UIImage {

    
    public enum Orientation : Int {

        
        case up = 0

        case down = 1

        case left = 2

        case right = 3

        case upMirrored = 4

        case downMirrored = 5

        case leftMirrored = 6

        case rightMirrored = 7
    }

    
    /* UIImage will implement the resizing mode the fastest way possible while
     retaining the desired visual appearance.
     Note that if an image's resizable area is one point then UIImageResizingModeTile
     is visually indistinguishable from UIImageResizingModeStretch.
     */
    public enum ResizingMode : Int {

        
        case tile = 0

        case stretch = 1
    }

    
    /* TARGET_ABI_USES_IOS_VALUES */
    
    /* TARGET_ABI_USES_IOS_VALUES */
    
    /* Images are created with UIImageRenderingModeAutomatic by default. An image with this mode is interpreted as a template image or an original image based on the context in which it is rendered. For example, navigation bars, tab bars, toolbars, and segmented controls automatically treat their foreground images as templates, while image views and web views treat their images as originals. You can use UIImageRenderingModeAlwaysTemplate to force your image to always be rendered as a template or UIImageRenderingModeAlwaysOriginal to force your image to always be rendered as an original.
     */
    @available(iOS 7.0, *)
    public enum RenderingMode : Int {

        
        case automatic = 0 // Use the default rendering mode for the context where the image is used

        
        case alwaysOriginal = 1 // Always draw the original image, without treating it as a template

        case alwaysTemplate = 2 // Always draw the image as a template image, ignoring its color information
    }

    
    /*
     * Retrieve a system-provided image with the specified name.
     * This will only return system-provided images. If you want a custom
     * image as defined in your own catalogs, you should use +imageNamed:.
     *
     * UIKit applications on macOS may pass NSImageName values (defined in
     * <AppKit/NSImage.h>) for the name to access macOS system images.
     *
     * Returns nil if an image with specified name doesn't exist.
     */
    
    // load from main bundle
    
    // reflects orientation setting. In iOS 4.0 and later, this is measured in points. In 3.x and earlier, measured in pixels
    // returns underlying CGImageRef or nil if CIImage based
    
    // returns underlying CIImage or nil if CGImageRef based
    
    // this will affect how the image is composited
    
    // animated images. When set as UIImageView.image, animation will play in an infinite loop until removed. Drawing will render the first image
    
    // read sequence of files with suffix starting at 0 or 1
    // sequence of files
    
    // default is nil for non-animated images
    // total duration for all frames. default is 0 for non-animated images
    
    // the these draw the image 'right side up' in the usual coordinate system with 'point' being the top-left.
    
    // mode = kCGBlendModeNormal, alpha = 1.0
    
    // mode = kCGBlendModeNormal, alpha = 1.0
    
    // draws the image as a CGPattern
    
    // create a resizable version of this image. the interior is tiled when drawn.
    // the interior is resized according to the resizingMode
    
    // default is UIEdgeInsetsZero for non resizable images
    // default is UIImageResizingModeTile
    
    // Support for constraint-based layout (auto layout)
    // The alignmentRectInsets of a UIImage are used by UIImageView and other UIView and UIControl
    //  subclasses that take custom images to determine the view's alignment rect insets for
    //  constraint-based layout.
    // The default alignmentRectInsets are UIEdgeInsetsZero.
    
    // Create a version of this image with the specified rendering mode. By default, images have a rendering mode of UIImageRenderingModeAutomatic.
    
    // Returns an optimal UIGraphicsImageRendererFormat instance for this image, maintaining pixel format and color space.
    
    // describes the image in terms of its traits
    // The asset is not encoded along with the image. Returns nil if the image is not CGImage based.
    
    // Creates a version of this image that, when assigned to a UIImageView’s image property, draws its underlying image contents horizontally mirrored when running under a right-to-left language. Affects the flipsForRightToLeftLayoutDirection property; does not affect the imageOrientation property.
    // This method cannot be used to create a left-to-right version of a right-to-left source image, and will be deprecated in a future release. New code should instead use -imageWithHorizontallyFlippedOrientation to construct a UIImageAsset.
    
    // Creates a version of this image with an imageOrientation property that is horizontally mirrored from this image’s. Does not affect the flipsForRightToLeftLayoutDirection property.
    
    /*
     * The baseline offset is expressed in points from the bottom of the image (positive = up, negative = down).
     * If the image doesn't have a defined baseline, this value will be 0, but you can
     * use -hasBaseline to see if it actually has one defined (because it is perfectly possible to have
     * a baseline with the value of 0).
     */
    
    /*
     * Configuration support
     * ---------------------
     * This describes the configuration of the image.
     * Depending on which type of image, the configuration might be different.
     * Symbol images will always have a UIImageSymbolConfiguration, even if you give it another
     * type of configuration (it will merge the trait info from the other configuration into
     * its current configuration).
     * Images start off with an unspecified configuration but can be modified by the methods below.
     * The preferred ways of adding configurations for displaying images is to specify them on
     * the image view, but it is possible to modify images with a more specific configuration.
     */
    
    /*
     * Create a new image by replacing the existing configuration with a new one.
     * For symbol images this will always result in an image with a UIImageSymbolConfiguration,
     * even if you give it another type of configuration (the trait info from the new configuration
     * will be merged into the current symbol configuration resulting in anew symbol configuration).
     * For non-symbol images, this will replace the configuration of the image with a new one.
     *
     * Important note! Given (for example):
     *
     *    image = image(named:"the_image").withRenderingMode(.alwaysTemplate)
    
     * the following two statements aren't exactly equivalent:
     *
     *    a = image.imageAsset.withConfiguration(configuration)
     *    b = image.withConfiguration(configuration)
     *
     * The first one will resolve the image again from the asset catalog (if it is originating from one),
     * resulting in a fresh image without any modifications. In other words, `a` won't have the
     * rendering mode change set anymore, and it will be "reverted" to `.automatic`.
     * The second one will resolve the image, but apply and changes that were made to the image.
     * That means that `b` might be a different image, but it will still have the same rendering mode
     * as `image`.
     */
    
    /*
     * Symbol configuration support
     * ----------------------------
     * This describes the symbol configuration of a symbol image.
     * Symbol images start off with an unspecified configuration but can be modified by using
     * `image.withConfiguration(:)`.
     *
     * However... the preferred ways of adding configurations for displaying images is to specify
     * them on the image view using `preferredSymbolConfiguration`, but it is possible to modify
     * images with a more specific configuration. This include image related traits, for example
     * you can use this to fix a symbol image to a dynamic type style at a fixed preferred content size
     * category.
     */
    
    /*
     * This is a convenience method to apply another symbol configuration over an existing one.
     * If the image doesn't have a symbol configuration, it will just merge the traits of the existing
     * with the new one (where the new traits override the old traits).
     *
     * Create a new image by applying the specified configuration over the existing one.
     * This only works if the configuration already has a configuration (i.e. is a symbol image).
     * The image will be configured with a combination of both configurations.
     *
     * If you use this on a symbol image with other layout modifications done (e.g. changed baseline),
     * those changes will be lost and overwritten with the new configuration's layout properties.
     * This applies to size, contentInsets and baseline.
     */
    
    /// Synchronously prepares this image for displaying on the specified screen.
    ///
    /// @return A UIImage object that contains the prepared image.
    ///
    /// @note The prepared UIImage is not related to the original image. If the properties of the screen (such as its resolution or color gamut) change, or if the image is displayed on a different screen that the one it was prepared for, it may not render correctly.
    
    /// Asynchronously prepares this image for displaying on the specified screen.
    ///
    /// The completion handler will be invoked on a private queue. Be sure to return to the main queue before assigning the prepared image to an image view.
    ///
    /// @param completionHandler A block to invoke with the prepared image. If preparation failed (for example, beacuse the image data is corrupt), @c image will be nil.
    ///
    /// @note The prepared UIImage is not related to the original image. If the properties of the screen (such as its resolution or color gamut) change, or if the image is displayed on a different screen that the one it was prepared for, it may not render correctly.
    
    // currently: white ellipsis on tinted filled circle
    // currently: white + on green filled circle
    // currently: white - on red filled circle
    // currently: white ✓ on tinted filled circle
    // currently: white ✓ on tinted filled and white stroked circle
    
    // use resizableImageWithCapInsets: and capInsets.
    
    // default is 0. if non-zero, horiz. stretchable. right cap is calculated as width - leftCapWidth - 1
    // default is 0. if non-zero, vert. stretchable. bottom cap is calculated as height - topCapWidth - 1
    
    public func pngData() -> Data? // return image as PNG. May return nil if image has no CGImageRef or invalid bitmap format

    public func jpegData(compressionQuality: CGFloat) -> Data? // return image as JPEG. May return nil if image has no CGImageRef or invalid bitmap format. compression is 0(most)..1(least)
}
@available(iOS 2.0, *)
open class UIImage : NSObject, NSSecureCoding {

    @available(iOS 13.0, *)
    public /*not inherited*/ init?(systemName name: String)

    @available(iOS 13.0, *)
    public /*not inherited*/ init?(systemName name: String, withConfiguration configuration: UIImage.Configuration?)

    @available(iOS 13.0, *)
    public /*not inherited*/ init?(systemName name: String, compatibleWith traitCollection: UITraitCollection?)

    public /*not inherited*/ init?(named name: String)

    @available(iOS 13.0, *)
    public /*not inherited*/ init?(named name: String, in bundle: Bundle?, with configuration: UIImage.Configuration?)

    @available(iOS 8.0, *)
    public /*not inherited*/ init?(named name: String, in bundle: Bundle?, compatibleWith traitCollection: UITraitCollection?)

    public init?(contentsOfFile path: String)

    public init?(data: Data)

    @available(iOS 6.0, *)
    public init?(data: Data, scale: CGFloat)

    public init(cgImage: CGImage)

    @available(iOS 4.0, *)
    public init(cgImage: CGImage, scale: CGFloat, orientation: UIImage.Orientation)

    @available(iOS 5.0, *)
    public init(ciImage: CIImage)

    @available(iOS 6.0, *)
    public init(ciImage: CIImage, scale: CGFloat, orientation: UIImage.Orientation)

    open var size: CGSize { get }

    open var cgImage: CGImage? { get }

    @available(iOS 5.0, *)
    open var ciImage: CIImage? { get }

    open var imageOrientation: UIImage.Orientation { get }

    @available(iOS 4.0, *)
    open var scale: CGFloat { get }

    @available(iOS 13.0, *)
    open var isSymbolImage: Bool { get }

    @available(iOS 5.0, *)
    open class func animatedImageNamed(_ name: String, duration: TimeInterval) -> UIImage?

    @available(iOS 5.0, *)
    open class func animatedResizableImageNamed(_ name: String, capInsets: UIEdgeInsets, duration: TimeInterval) -> UIImage?

    @available(iOS 6.0, *)
    open class func animatedResizableImageNamed(_ name: String, capInsets: UIEdgeInsets, resizingMode: UIImage.ResizingMode, duration: TimeInterval) -> UIImage?

    @available(iOS 5.0, *)
    open class func animatedImage(with images: [UIImage], duration: TimeInterval) -> UIImage?

    @available(iOS 5.0, *)
    open var images: [UIImage]? { get }

    @available(iOS 5.0, *)
    open var duration: TimeInterval { get }

    open func draw(at point: CGPoint)

    open func draw(at point: CGPoint, blendMode: CGBlendMode, alpha: CGFloat)

    open func draw(in rect: CGRect)

    open func draw(in rect: CGRect, blendMode: CGBlendMode, alpha: CGFloat)

    open func drawAsPattern(in rect: CGRect)

    @available(iOS 5.0, *)
    open func resizableImage(withCapInsets capInsets: UIEdgeInsets) -> UIImage

    @available(iOS 6.0, *)
    open func resizableImage(withCapInsets capInsets: UIEdgeInsets, resizingMode: UIImage.ResizingMode) -> UIImage

    @available(iOS 5.0, *)
    open var capInsets: UIEdgeInsets { get }

    @available(iOS 6.0, *)
    open var resizingMode: UIImage.ResizingMode { get }

    @available(iOS 6.0, *)
    open func withAlignmentRectInsets(_ alignmentInsets: UIEdgeInsets) -> UIImage

    @available(iOS 6.0, *)
    open var alignmentRectInsets: UIEdgeInsets { get }

    @available(iOS 7.0, *)
    open func withRenderingMode(_ renderingMode: UIImage.RenderingMode) -> UIImage

    @available(iOS 7.0, *)
    open var renderingMode: UIImage.RenderingMode { get }

    @available(iOS 10.0, *)
    open var imageRendererFormat: UIGraphicsImageRendererFormat { get }

    @available(iOS 8.0, *)
    @NSCopying open var traitCollection: UITraitCollection { get }

    @available(iOS 8.0, *)
    open var imageAsset: UIImageAsset? { get }

    @available(iOS 9.0, *)
    open func imageFlippedForRightToLeftLayoutDirection() -> UIImage

    @available(iOS 9.0, *)
    open var flipsForRightToLeftLayoutDirection: Bool { get }

    @available(iOS 10.0, *)
    open func withHorizontallyFlippedOrientation() -> UIImage

    @available(iOS 13.0, *)
    open func withBaselineOffset(fromBottom baselineOffset: CGFloat) -> UIImage

    @available(iOS 13.0, *)
    open func imageWithoutBaseline() -> UIImage

    @available(iOS 13.0, *)
    @NSCopying open var configuration: UIImage.Configuration? { get }

    @available(iOS 13.0, *)
    open func withConfiguration(_ configuration: UIImage.Configuration) -> UIImage

    @available(iOS 13.0, *)
    @NSCopying open var symbolConfiguration: UIImage.SymbolConfiguration? { get }

    @available(iOS 13.0, *)
    open func applyingSymbolConfiguration(_ configuration: UIImage.SymbolConfiguration) -> UIImage?

    @available(iOS 13.0, *)
    open func withTintColor(_ color: UIColor) -> UIImage

    @available(iOS 13.0, *)
    open func withTintColor(_ color: UIColor, renderingMode: UIImage.RenderingMode) -> UIImage

    /// Synchronously prepares this image for displaying on the specified screen.
    ///
    /// @return A UIImage object that contains the prepared image.
    ///
    /// @note The prepared UIImage is not related to the original image. If the properties of the screen (such as its resolution or color gamut) change, or if the image is displayed on a different screen that the one it was prepared for, it may not render correctly.
    @available(iOS 15.0, *)
    open func preparingForDisplay() -> UIImage?

    /// Asynchronously prepares this image for displaying on the specified screen.
    ///
    /// The completion handler will be invoked on a private queue. Be sure to return to the main queue before assigning the prepared image to an image view.
    ///
    /// @param completionHandler A block to invoke with the prepared image. If preparation failed (for example, beacuse the image data is corrupt), @c image will be nil.
    ///
    /// @note The prepared UIImage is not related to the original image. If the properties of the screen (such as its resolution or color gamut) change, or if the image is displayed on a different screen that the one it was prepared for, it may not render correctly.
    @available(iOS 15.0, *)
    open func prepareForDisplay(completionHandler: @escaping (UIImage?) -> Void)

    /// Asynchronously prepares this image for displaying on the specified screen.
    ///
    /// The completion handler will be invoked on a private queue. Be sure to return to the main queue before assigning the prepared image to an image view.
    ///
    /// @param completionHandler A block to invoke with the prepared image. If preparation failed (for example, beacuse the image data is corrupt), @c image will be nil.
    ///
    /// @note The prepared UIImage is not related to the original image. If the properties of the screen (such as its resolution or color gamut) change, or if the image is displayed on a different screen that the one it was prepared for, it may not render correctly.
    @available(iOS 15.0, *)
    open func byPreparingForDisplay() async -> UIImage?

    @available(iOS 15.0, *)
    open func preparingThumbnail(of size: CGSize) -> UIImage?

    @available(iOS 15.0, *)
    open func prepareThumbnail(of size: CGSize, completionHandler: @escaping (UIImage?) -> Void)

    @available(iOS 15.0, *)
    open func byPreparingThumbnail(ofSize size: CGSize) async -> UIImage?
}

extension UIImage {

    /// Creates an instance initialized with the given resource name.
    ///
    /// Do not call this initializer directly. Instead, initialize a variable or
    /// constant using an image literal.
    required public convenience init(imageLiteralResourceName name: String)
}

@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension UIImage {

    public var baselineOffsetFromBottom: CGFloat? { get }
}
extension UIImage {

    @available(iOS 13.0, *)
    open class var actions: UIImage { get }

    @available(iOS 13.0, *)
    open class var add: UIImage { get }

    @available(iOS 13.0, *)
    open class var remove: UIImage { get }

    @available(iOS 13.0, *)
    open class var checkmark: UIImage { get }

    @available(iOS 13.0, *)
    open class var strokedCheckmark: UIImage { get }
}
extension UIImage : NSItemProviderReading, NSItemProviderWriting, UIItemProviderPresentationSizeProviding {
}
extension NSTextAttachment {

    @available(iOS 13.0, *)
    public /*not inherited*/ init(image: UIImage)
}
extension UIImage {

    open func stretchableImage(withLeftCapWidth leftCapWidth: Int, topCapHeight: Int) -> UIImage

    open var leftCapWidth: Int { get }

    open var topCapHeight: Int { get }
}
extension CIImage {

    @available(iOS 5.0, *)
    public init?(image: UIImage)

    @available(iOS 5.0, *)
    public init?(image: UIImage, options: [CIImageOption : Any]? = nil)
}
